package Demo_2;

public class Demo_Thread {
    public static void main(String[] args) {
        //1.匿名内部类创建Thread对象
        Thread thread = new Thread(){
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("hello Thread...");
                }
            }
        };
        //2.匿名内部类创建Runnable子类，实现Runnable接口,并重写run方法
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("hello Runnable...");
                }
            }
        });
        //3.Lambda表达式创建
        Thread thread2 = new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("hello lambda...");
            }
        });
        thread.start();
        thread1.start();
        thread2.start();
    }
}
